<!DOCTYPE html>
<html lang="zh">
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>Document</title>
		<link href="/static/layui/css/layui.css" rel="stylesheet">
		<script src="http://code.jquery.com/jquery-latest.js"></script>
		<!-- 引入 layui.js -->
		<script src="/static/layui/layui.js"></script>
	</head>
	<body>
		<form class="layui-form layui-form-pane" style="padding: 20px;" action="">
			<div class="layui-form-item">
				<label class="layui-form-label">平台</label>
				<div class="layui-input-block">
					
					<select lay-search="" name="platform" lay-filter="platform" lay-verify="required">
						<option value="">请选择电商平台</option>
						{volist name="platform" id="vo"}
						<option value="{$vo.platform}">{$vo.platform}</option>
						{/volist}
					</select>
					
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-block">
					<input type="text" name="order_number" autocomplete="off" placeholder="请输入订单号" lay-verify="required"
						class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">发货时间</label>
				<div class="layui-input-block">
					<input type="text" name="delivery_time" autocomplete="off" class="layui-input" id="ID-laydate-demo"
						placeholder="yyyy-MM-dd" lay-verify="required">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">产品名称</label>
					<div class="layui-input-block">
						<select lay-search="" name="product_name" lay-filter="product_name" lay-verify="required">
							<option value="">请选择产品名称</option>
							{volist name="product" id="vo"}
							<option value="{$vo.product_name}({$vo.net_content})">{$vo.product_name}_{$vo.net_content}</option>
							{/volist}
						</select>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">产品数量</label>
					<div class="layui-input-inline">
						<input type="number" name="total_quantity" placeholder="请输入产品数量" autocomplete="off"
							lay-verify="required" class="layui-input">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">收件信息</label>
				<div class="layui-input-block">
					<input type="text" name="receiving_information" autocomplete="off" placeholder="请输入收件信息"
						lay-verify="required" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">快递公司</label>
					<div class="layui-input-block">
						<input type="text" name="express_company" placeholder="快递公司自动识别" autocomplete="off"
							lay-verify="required" class="layui-input" id="kdgs" disabled>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">运单号</label>
					<div class="layui-input-inline">
						<input type="text" name="hwb_number" placeholder="请输入运单号" autocomplete="off"
							lay-verify="required" class="layui-input" id="nu">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">手机尾号</label>
				<div class="layui-input-block">
					<input type="number" autocomplete="off" placeholder="请输入手机后4位" class="layui-input" value="5626" id="ws4">
					<span style="color: red;">(此手机尾号为发件人手机尾号用于查询顺丰快递验证，其他快递无需验证手机尾号)</span>
				</div>
			</div>
			<div class="layui-form-item" pane>
				<label class="layui-form-label">售后状态</label>
				<div class="layui-input-block">
					<input type="radio" name="status" value="0" title="仅退款" checked>
					<input type="radio" name="status" value="1" title="退货退款">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">退款原因</label>
				<div class="layui-input-block">
					<input type="text" name="after_sales_reason" autocomplete="off" placeholder="请输入售后原因"
						lay-verify="required" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" pane>
				<label class="layui-form-label">退回方式</label>
				<div class="layui-input-block">
					<div class="layui-input-block">
						<input type="radio" name="return_mode" value="0" title="拦截退回" checked>
						<input type="radio" name="return_mode" value="1" title="客户自行退回">
						<input type="radio" name="return_mode" value="2" title="客户拒收退回">
						<input type="radio" name="return_mode" value="3" title="异常处理退回">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">退回快递公司</label>
					<div class="layui-input-block">
						<input type="text" name="return_to_courier" placeholder="快递公司自动识别" autocomplete="off"
							lay-verify="required" class="layui-input" id="kdgsA" disabled>
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">退回运单号</label>
					<div class="layui-input-inline">
						<input type="text" name="return_hwb_number" placeholder="请输入退回运单号" autocomplete="off"
							class="layui-input" id="nuA">
					</div>
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<input type="text" name="remark" autocomplete="off" placeholder="请输入售后原因" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item" pane>
				<label class="layui-form-label">退回状态</label>
				<div class="layui-input-block">
					<input type="radio" name="back_state" value="0" title="退回中" checked>
					<input type="radio" name="back_state" value="1" title="已收到退件">
				</div>
			</div>
			<div class="layui-form-item">
				<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-add" id="btn">添加</button>
			</div>
		</form>
		<script type="text/javascript">
			$(document).ready(function() {
				$('#nu').blur(function() {
					var nu = $("#nu").val();
					/* var ws4 = $("#ws4").val(); */
					if(nu.substring(0, 2)=="SF"){
						var ws1 = $("#ws4").val();
					}
					$.ajax({
						url: 'https://api.songzixian.com/api/express-tracking?dataSource=nationwide_express',
						type: 'GET',
						data: {
							trackingNumber: nu,
							phoneLast4: ws1
						},
						dataType: 'json',
						success: function(data) {
							if (data.code === 200) {
								//layer.msg(data.message, {icon: 1},{time: 3000});
								var loadIndex = layer.msg('识别中', {icon: 16,shade: 0.01});
								      setTimeout(function(){
								        layer.close(loadIndex);
										$(document).ready(function() {
											$('#kdgs').val(data.data.courierName);
										});
								      }, 1500);
								
								

							} else {
								layer.msg(data.message, {
									icon: 0
								}, {
									time: 3000
								});
							}
						},
						error: function() {
							// 处理错误
							$('#result').html('查询出错');
						}
					});


				});
				
				$('#nuA').blur(function() {
					var nu = $("#nuA").val();
					/* var ws4 = $("#ws4").val(); */
					if(nu.substring(0, 2)=="SF"){
						var ws1 = $("#ws4").val();
					}
					$.ajax({
						url: 'https://api.songzixian.com/api/express-tracking?dataSource=nationwide_express',
						type: 'GET',
						data: {
							trackingNumber: nu,
							phoneLast4: ws1
						},
						dataType: 'json',
						success: function(data) {
							if (data.code === 200) {
								//layer.msg(data.message, {icon: 1},{time: 3000});
								var loadIndex = layer.msg('识别中', {icon: 16,shade: 0.01});
								      setTimeout(function(){
								        layer.close(loadIndex);
										$(document).ready(function() {
											$('#kdgsA').val(data.data.courierName);
										});
								      }, 1500);
							} else {
								layer.msg(data.message, {
									icon: 0
								}, {
									time: 3000
								});
							}
						},
						error: function() {
							// 处理错误
							$('#result').html('查询出错');
						}
					});
				
				
				});
			})
			layui.use(function() {
				var laydate = layui.laydate;
				var form = layui.form;
				var layer = layui.layer;
				// 渲染
				laydate.render({
					elem: '#ID-laydate-demo'
				});
				form.on('submit(demo-add)', function(data) {
					var field = data.field;
					var index = parent.layer.getFrameIndex(window.name);

					/* layer.alert(JSON.stringify(field), {
					      title: '当前填写的字段值'
					    }); */
					$.ajax({
						url: '{:url("Returntable/adddata")}',
						type: 'post',
						data: field,
						dataType: 'json',
						success: function(res) {
							if (res.code == 200) {
								layer.msg(res.msg, {
									time: 500
								}, function() {
									/* parent.layui.table.reload('tablea'); */
									window.parent.location.reload();
									parent.layer.close(index);

								});
							} else {
								layer.msg(res.msg);
							}
						}
					});
					return false; // 阻止默认 form 跳转
				});
			});
		</script>
	</body>
</html>